package com.yingxue.demo.controller;

import com.yingxue.demo.constant.Constant;
import com.yingxue.demo.service.HomeService;
import com.yingxue.demo.util.JWTUtil;
import com.yingxue.demo.util.ResultVOUtil;
import com.yingxue.demo.vo.resp.HomeRespVO;
import com.yingxue.demo.vo.resp.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Package: com.yingxue.demo.controller
 * @Author: Mr.Waves
 * @Date: 2020-03-31 11:07
 * @Description:
 **/
@RestController
@RequestMapping("api")
public class HomeController {
    @Autowired
    private HomeService homeService;

    @GetMapping("home")
    public ResultVO<HomeRespVO> getHomeData(HttpServletRequest request) {
        String accessToken = request.getHeader(Constant.ACCESS_TOKEN);
        String userId = JWTUtil.getUserId(accessToken);
        HomeRespVO homeData = homeService.getHomeDataByUserId(Long.valueOf(userId));
        return ResultVOUtil.success(homeData);
    }

}
